﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Nhom14_HTTTHD_BuyMe
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Info_submit_Click(object sender, EventArgs e)
        {
            string par1 = Info_email.Text;
            string par2 = Info_Password.Text;

            string address = "http://localhost:49744/WebService1.asmx";
            string function = "Login";

            int res = (int)WebserviceInvoker.WSInvoker.CallWebService(address, "WebService1", function, new object[] { par1, par2 });

            if (res != 0)
            {
                using (websitebrokenEntities context = new websitebrokenEntities())
                {
                    account obj = new account();
                    var kq = from s in context.accounts
                             where s.id == res
                             select s;
                    obj = kq.First();
                    Session["login"] = "1";
                    Session["user"] = obj.id.ToString();
                    Session["name"] = obj.firstname;
                    Session["credit"] = obj.credit;
                }                
                if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                    Response.Redirect(Request.QueryString["url"]);
                else Response.Redirect("Default.aspx");
            }
            else
            {
                Label1.Text = "Username or password is wrong! Please try again!";
            }            
        }
    }
}